/**
 * build mohui
 */

'use strict';

var gulp = require('gulp');
var runSequence = require('run-sequence');
var util = require('./util');
var config = require('./config');

// load special build task
gulp = require('./build_task')(gulp, config.SRC_PATH, config.DIST_PATH);

// watch
gulp.task('watch', function (cb) {
    //$.livereload.listen(); //自动刷新
    var watcher = gulp.watch([
            config.SRC_PATH + 'scss/**/*.scss',
            config.SRC_PATH + 'html/*.html', 
            config.SRC_PATH + 'html/**/*.html', 
            config.SRC_PATH + 'js/**/*.js',
            "!"+ config.SRC_PATH + 'js/*.min.js'
        ],
        ['build_html']
    );

    watcher.on('change', function(event) {
 /*       setTimeout(function(){
            $.livereload.changed(event.path);  //要一定延迟，保存流处理全部ok
        },1000);*/
        console.log('File ' + event.path + ' was ' + event.type + ', running tasks...');
    });

});

// Build Task
gulp.task('build', ['clean'], function (cb) {
    runSequence('build_html', 'watch', cb);
});

// log
util.logGulpEvents(gulp);

// run
gulp.run(['build']);

